package core;

/**
 * Represents an abstract attribute; an attribute consists of a name and a
 * (possibly null) value.  Attributes are used to store any information
 * that GameObjects need to maintain.
 */
public abstract class Attribute<T> extends GameObject
{
	/**
	 * Construct an Attribute with the given value.
	 * @param name a String
	 */
	public Attribute(String name) {
		this(name, null);
	}

	public Attribute(String name, T value) {
		super(name);
		setValue(value);
	}

	/**
	 * Set the value of this attribute
	 * @param value
	 */
	public void setValue(T value) {
		this.value = value;
	}

	/**
	 * @return Returns the String representation of the current value.
	 */
	public T getValue() {
		return value;
	}

	public abstract T parseString(String stringValue);
	
	/**
	 * Adding attributes is not supported for Attributes.
	 * @throws UnsupportedOperationException
	 */
	public void addAttribute() {
		throw new UnsupportedOperationException("Attempted to add an attribute to another attribute.");
	}

	public String toString() {
		return getName() + " = " + ((getValue() == null) ? "null" : getValue().toString());
	}

	public GameObject getParent() {
		return parent;
	}

	protected GameObject parent = null;
	private T value;
}